home *** CD-ROM | disk | FTP | other *** search
- #include <threads.h>
- #include <stdio.h>
- #include <GestaltEqu.h>
-
- #if defined(powerc) || defined (__powerc)
- #include <FragLoad.h>
- #endif
-
- pascal void *MyThread_A( void *refCon);
- pascal void *MyThread_B( void *refCon);
- pascal void *MyThread_C( void *refCon);
-
- void main( void)
- {
- OSErr errWhatErr;
- int i;
- ThreadID threadID_A, threadID_B, threadID_C;
- long threadGestaltInfo;
-
- // Test for the presence of the threads manager
- // 1. Is the gestalt selector defined? If not, we bail immediately
- // 2. If we're compiling PPC native code, then check for the ThreadsLibrary
- // 3. Also, if we're native, check that CFM actually linked my app to the library
- // 4. Is the Thread Mgr Present bit set to True? If not, bail
-
- if( Gestalt( gestaltThreadMgrAttr, &threadGestaltInfo) != noErr ||
- #if defined(powerc) || defined (__powerc)
- threadGestaltInfo & (1<<gestaltThreadsLibraryPresent) == 0 ||
- (Ptr) NewThread == kUnresolvedSymbolAddress ||
- #endif
- threadGestaltInfo & (1<<gestaltThreadMgrPresent) == 0)
- {
- // This is the bail clause. Yours may be more elaborate
- printf( "The Threads Mgr isn't present... Can't run the test.\n");
- return;
- }
-
- // Create 3 threads: A, B, C
- errWhatErr = NewThread( kCooperativeThread, MyThread_A, (void *)0, 0,
- kFPUNotNeeded + kCreateIfNeeded,
- (void**)nil, &threadID_A);
-
- errWhatErr = NewThread( kCooperativeThread, MyThread_B, (void *)0, 0,
- kFPUNotNeeded + kCreateIfNeeded,
- (void**)nil, &threadID_B);
-
- errWhatErr = NewThread( kCooperativeThread, MyThread_C, (void *)0, 0,
- kFPUNotNeeded + kCreateIfNeeded,
- (void**)nil, &threadID_C);
-
- // Simple loop to test Yielding
- for( i = 0; i < 5; i++) {
- printf( "This is thread main\n");
- YieldToAnyThread();
- }
- }
-
- pascal void *MyThread_A( void * /* refCon */)
- {
- int i;
-
- for( i = 0; i < 5; i++) {
- printf( "------- A ------\n");
- YieldToAnyThread();
- }
-
- return nil;
- }
-
- pascal void *MyThread_B( void * /* refCon */)
- {
- int i;
-
- for( i = 0; i < 5; i++) {
- printf( "------- B ------\n");
- YieldToAnyThread();
- }
-
- return nil;
- }
-
- pascal void *MyThread_C( void * /* refCon */)
- {
- int i;
-
- for( i = 0; i < 5; i++) {
- printf( "------- C ------\n");
- YieldToAnyThread();
- }
-
- return nil;
- }
-